<template>
	<view>
		<web-view :src="webSrc" bindmessage="postMessage"></web-view>
	</view>
</template>
<script>
	import {
		getwxOpenid
	} from "@/request/api.js";
	export default {
		name: "h5-author",
		data() {
			return {
				webSrc: "", // 授权链接
			};
		},
		onLoad(e) {
			console.log(e, e.code, 'e.code')
			if (e.code) {
				getwxOpenid({
					code: e.code
				}).then((res) => {
					if (res.code == 200) {
						uni.switchTab({
							url: "/pages/my/my",
						});
					} else {
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1500);
					}
				})
			} else {
				this.webSrc = "https://txh5.westts.cn/author.html";
				console.log(this.webSrc,'this.webSrc')
			}
		},
		methods: {
			postMessage(e) {
				console.log("获取H5消息", e);
			},
		},
	};
</script>